﻿using IOA.MES.Client.Common;
using IOA.MES.Client.Settings;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace IOA.MES.Client
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private bool machineTypeValid = false;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void btnMenu_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var btn = (StackPanel)sender;
            var btnName = btn.Name?.Trim().ToLower();
            this.Hide();
            switch (btnName)
            {
                case "btnwelding":
                    //焊接
                    new Welding.WeldingIndex().ShowDialog();
                    break;
                case "btnlaminator":
                    //叠层
                    new Laminator.LaminatorIndex().ShowDialog();
                    break;
                case "btnel1":
                    //EL1
                    new EL1.EL1Index().ShowDialog();
                    break;
                case "btntop":
                    //层压
                    new Top.TopIndex().ShowDialog();
                    break;
                case "btnnqc":
                    //NQC
                    new NQC.NQCIndex().ShowDialog();
                    break;
                case "btnframing":
                    //装框
                    new Framing.FramingIndex().ShowDialog();
                    break;
                case "btnclean":
                    //清洗
                    new Clean.CleanIndex().ShowDialog();
                    break;
                case "btnivtest":
                    //IV测试
                    new IV.IVIndex().ShowDialog();
                    break;
                case "btninsulatedresistance":
                    //绝缘耐压
                    new InsulatedResistance.InsulatedResistanceIndex().ShowDialog();
                    break;
                case "btnel2":
                    //EL2
                    new EL2.EL2Index().ShowDialog();
                    break;
                case "btnnameplateprinting":
                    //铭牌打印
                    new NameplatePrinting.NameplatePrintingIndex().ShowDialog();
                    break;
                case "btnfinalinspection":
                    //终检
                    new FinalInspection.FinalInspectionIndex().ShowDialog();
                    break;
            }
            this.Show();
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void Menu_Click(object sender, RoutedEventArgs e)
        {
            var btnMenu = sender as MenuItem;
            switch (btnMenu.Name)
            {
                case "btnSettings":
                    var result = new SettingsIndex().ShowDialog();
                    if (result == true)
                    {
                        CommonMessage.Alert(this, "请重新登录！");
                        Environment.Exit(0);
                    }
                    break;
            }
        }
    }
}
